package com.wyh.controller;

import com.baomidou.mybatisplus.core.conditions.AbstractWrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.easemob.im.server.EMService;
import com.easemob.im.server.api.token.Token;
import com.easemob.im.server.model.EMUser;
import com.easemob.im.shaded.reactor.core.publisher.Mono;
import com.wyh.common.constant.Constant;
import com.wyh.entity.AdminUser;
import com.wyh.framework.redis.RedisCache;
import com.wyh.mapper.AdminUserMapper;
import com.wyh.vo.LoginVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @Author 汪宇航
 * @Date 2024/3/7 11:41
 * @Version 1.5
 */
@RestController
@RequestMapping("/imUser")
public class UserController {


    @Autowired
    private RedisCache redisCache;

    private AdminUserMapper adminUserMapper;

    @Autowired
    private EMService service;

    /**
     * 创建用户
     */
    @RequestMapping("/add")
    public String createUser(){
        String token = service.token().getUserTokenWithInherit("wang");
        AdminUser adminUser = adminUserMapper.selectOne(Wrappers.lambdaQuery(AdminUser.class).eq(AdminUser::getUserId, "wang"));
        LoginVo loginVo = new LoginVo();
        BeanUtils.copyProperties(adminUser,loginVo);
        redisCache.setCacheObject(Constant.USER_TOKEN_CACHE + adminUser.getUserId(), token,100 , TimeUnit.MINUTES);

        return null;
    }

}
